package com.gitee.itembucket.util.germ

import com.germ.germplugin.api.dynamic.gui.GermGuiInput
import com.germ.germplugin.api.dynamic.gui.GermGuiItem
import com.germ.germplugin.api.dynamic.gui.GermGuiScreen
import com.gitee.itembucket.util.germ.germ.GermPartDSL
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import taboolib.library.configuration.ConfigurationSection

class GermInputDSL : GermPartDSL<GermGuiInput>() {

    var width = ""
    var height = ""
    var size = "1"
    var item: ItemStack? = null
    val tooltip = mutableListOf<String>()
    var autoClear: Boolean = true
    var replaceColor: Boolean = false
    var background: Boolean = true
    var preview = ""
    var limit = 32
    var focus = false
    var permanentFocus = false
    var regular: String? = null
    var sync = false
    var input = ""
    var autoWrap = false
    var swallow = true
    var invalid = false

    var onenter : ((Player,GermGuiInput) -> Unit)? = null

    override val type: String = "texture"

    override fun infuse(config: ConfigurationSection) {
        name = config.name
        config.getString("locationX")?.let { locationX = it }
        config.getString("locationY")?.let { locationY = it }
        config.getString("locationZ")?.let { locationZ = it }
        config.getString("size")?.let { size = it }
        config.getString("width")?.let { width = it }
        config.getString("height")?.let { height = it }
        config.getString("width")?.let { width = it }

        autoClear = config.getBoolean("autoClear", true)
        replaceColor = config.getBoolean("replaceColor", false)
        background = config.getBoolean("background", true)
        swallow = config.getBoolean("background", swallow)
        focus = config.getBoolean("focus", false)
        permanentFocus = config.getBoolean("permanentFocus", false)
        sync = config.getBoolean("sync", false)
        autoWrap = config.getBoolean("autoWrap", false)
        invalid = config.getBoolean("invalid", false)
        preview = config.getString("preview", "")!!
        input = config.getString("input", "")!!
        limit = config.getInt("limit", 32)
        tooltip += config.getStringList("tooltip")
        regular = config.getString("regular")


        enable = config.getBoolean("enable")
    }

    override fun create(): GermGuiInput {
        return GermGuiInput(name).also {
            it.locationX = locationX
            it.locationY = locationY
            it.locationZ = locationZ
            it.enable = enable
            it.width = width
            it.height = height
            it.isAutoClear = autoClear
            it.isReplaceColor = replaceColor
            it.isBackground = background
            it.isSwallow = swallow
            it.isFocus = focus
            it.isPermanentFocus = permanentFocus
            it.isSync = sync
            it.isAutoWrap = autoWrap
            it.isInvalid = invalid
            it.preview = preview
            it.input = input
            it.limit = limit
            it.tooltip = tooltip
            it.regular = regular
            onenter?.let { onenter ->
                it.registerCallbackHandler({player,input -> onenter(player,input)},GermGuiInput.EventType.ENTER)
            }
        }
    }
}